package com.hongdee.insurance.contract.mapper;

import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

/**
 * Created by Liu XiaoLong
 * Date: 2017/11/10.
 * Remark:
 */
public class TInsuranceCompanyContractQuery {
    public String list(Map map) {

        Map data = (Map) map.get("data");
        SQL sql = new SQL() {{
            SELECT(" c.*,p.province provinceName,i.city cityName ");
            FROM("t_insurance_company_contract c  " +
                    " left join t_bc_provinces p on c.province = p.provinceid  " +
                    " left JOIN t_bc_cities i on c.city =CONVERT(i.cityid USING utf8) COLLATE utf8_unicode_ci ");

            if (!data.get("year").toString().isEmpty())
            {
                WHERE("c.year = #{data.year}");
            }

            if (!data.get("area").toString().isEmpty())
            {
                WHERE("c.area = #{data.area}");
            }

            if (!data.get("insuranceCompany").toString().isEmpty())
            {
                WHERE("c.insurance_company_id = #{data.insuranceCompany}");
            }
        }};
        return sql.toString();
    }

}
